<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>公告管理</title>
    <link href="/static/assets/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="/static/css/style.css" rel="stylesheet">
    <link href="/static/css/colors/blue.css" id="theme" rel="stylesheet">
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body class="fix-header card-no-border">
<!-- 顶部 -->
<div id="main-wrapper">
    <header class="topbar">
        <nav class="navbar top-navbar navbar-toggleable-sm navbar-light">
            <div class="navbar-collapse">
                <ul class="navbar-nav my-lg-0">
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle text-muted waves-effect waves-dark" href=""
                           data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">欢迎您，管理员！</a>
                    </li>
                </ul>
            </div>
        </nav>
    </header>
    <aside class="left-sidebar">
        <div class="scroll-sidebar">
            <nav class="sidebar-nav">
                <ul id="sidebarnav">
                    <li>
                        <a href="/admin-home" class="waves-effect"><i class="fa fa-clock-o m-r-10"
                                                                      aria-hidden="true"></i>帖子管理</a>
                    </li>
                    <li class="active">
                        <a href="/announcement" class="waves-effect"><i class="fa fa-user m-r-10"
                                                                        aria-hidden="true"></i>公告管理</a>
                    </li>
                    <li>
                        <a href="/kind-manage" class="waves-effect"><i class="fa fa-table m-r-10"
                                                                       aria-hidden="true"></i>板块管理</a>
                    </li>
                </ul>
            </nav>
        </div>
    </aside>
    <div class="page-wrapper">
        <div class="container-fluid">
            <div class="row page-titles">
                <div class="col-md-6 col-8 align-self-center">
                    <h3 class="text-themecolor m-b-0 m-t-0">公告管理</h3>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-12">
                    <div class="card">
                        <div class="card-block">
                            <div class="table-responsive">
                                <table class="table">
                                    <thead>
                                    <tr>
                                        <th style="width: 10%;">序号</th>
                                        <th>标题</th>
                                        <th style="width: 25%;text-align: right;"></th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    {% for announcement in announcements %}
                                        <tr>
                                            <td>{{ announcement.id }}</td>
                                            <td>{{ announcement.a_title }}</td>
                                            <td>
                                                <a href="/single-an-{{ announcement.id }}">
                                                    <button class="btn" style="float: right;">查看</button>
                                                </a>
                                                <button class="btn delete" style="float: right;"
                                                        onclick="deletea(this);" iddd="{{ announcement.id }}">删除
                                                </button>
                                            </td>
                                        </tr>
                                    {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


            <!-- Row -->
            <div class="row">
                <div style="width: 100%">
                    <div class="card">
                        <div class="card-block">
                            <form class="form-horizontal form-material">
                                <span>添加公告</span>

                                <div class="form-group" style="margin-top: 10px">
                                    <label class="col-md-12">标题</label>
                                    <div class="col-md-12">
                                        <input id="a_title" type="text" placeholder=""
                                               class="form-control form-control-line">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-12">公告内容</label>
                                    <div class="col-md-12">
                                        <textarea id="a_content" rows="5"
                                                  class="form-control form-control-line"></textarea>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-12">
                                        <button id="publisha" class="btn btn-success">发布公告</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>

            </div>
        </div>
        <footer class="footer text-center">
            © 2020 交流论坛
        </footer>
    </div>
</div>
<script src="/static/assets/plugins/jquery/jquery.min.js"></script>
<script src="/static/assets/plugins/bootstrap/js/tether.min.js"></script>
<script src="/static/assets/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="/static/js/jquery.slimscroll.js"></script>
<script src="/static/js/waves.js"></script>
<script src="/static/js/sidebarmenu.js"></script>
<script src="/static/assets/plugins/sticky-kit-master/dist/sticky-kit.min.js"></script>
<script src="/static/js/custom.min.js"></script>
<script src="/static/assets/plugins/styleswitcher/jQuery.style.switcher.js"></script>


<script>
    function deletea(ths) {
        var aid = $(ths).attr("iddd");
        alert(aid);
        $.ajax({
            url: window.location.href,
            type: "POST",
            data: {'type': 'delete', 'a_id': aid},
            beforeSend: function (xhr, settings) {
                xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");    // csrf
            },
            success: function (data) {
                // data是服务器端返回的字符串
                var dic = JSON.parse(data)
                if (!dic.status) alert(JSON.parse(data).msg);
                else window.location.href = "/announcement";
            }
        });
    }

    $('#publisha').click(function () {
        var a_title = $('#a_title').val();
        var a_content = $('#a_content').val();
        $.ajax({
            url: window.location.href,
            type: "POST",
            data: {'type': 'create', 'a_content': a_content, 'a_title': a_title},
            beforeSend: function (xhr, settings) {
                xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");    // csrf
            },
            success: function (data) {
                // data是服务器端返回的字符串
                var dic = JSON.parse(data);
                if (!dic.status) alert(JSON.parse(data).msg);
                else window.location.href = "/announcement";
            }
        });
    });
</script>
</body>

</html>
